var ws = {};
ws.emailREG = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
ws.alertObj = {};
ws.alertTimeOut = null;

ws.alert = function(input, msg) {
	var id = $(input).attr("id");
	    ws.alertClose(input);
		ws.alertObj[id] = $("<div class='alert' id='alert_"+id+"'>" + msg + "</div>").css({
			left: $(input).offset().left,
			top: $(input).offset().top - 40
	        })
        $(document.body).append(ws.alertObj[id]);
        window.setTimeout(function(){
           // ws.alertClose(input)
        },3000)
	}

ws.alertClose = function(input) {
	var id = $(input).attr("id");
	$("#alert_"+id).remove();
}
ws.checkEmail2 = function(input){
    var $input = $(input);
    if(!ws.emailREG.test($input.val())){
        ws.alert($input, "请输入正确的邮箱地址");
        ws.setError($input)
        return false;
    }else{
        ws.alertClose(input);
         ws.removeError($input)
        return false;
    }
}
ws.checkEmail = function(input){

    var $input = $(input);
    if(!ws.emailREG.test($input.val())){
        ws.alert($input, "请输入正确的邮箱地址");
        ws.setError($input)
        return false;
    }else{
        $.get("/user/checkMail.action",{
            mail: $input.val()
        },function(data){
                if(data=="true"){
                    ws.alert($input, "该邮箱已经注册");
                    ws.setError($input)
                    return false;
                }else{
                    ws.alertClose(input);
                    ws.removeError($input)
                    return false;
                }
            })
        return false;
    }
}

ws.checkPassword = function(input){
    var $input = $(input);
    if($.trim($input.val()).length<6){
        ws.alert($input, "密码不能少于6位");
        ws.setError($input)
        return false;
    }else{
        ws.alertClose(input);
        ws.removeError($input)
        return false;
    }
}

ws.checkPassword1 = function(input){
    var $input = $(input);
    if($input.val() !== $("#pword").val()){
        ws.alert($input, "密码不一致");
        ws.setError($input)
        return false;
    }else{
        ws.alertClose(input);
        ws.removeError($input)
        return false;
    }
}

ws.setError = function(input){
    input.addClass("error").focus();
    }
ws.removeError = function(input){
    input.removeClass("error")
}

ws.regFrom = function() {
	var regInput = $(".reg-box").find("input");
	regInput.data("error", "true");
	regInput.focus(function() {
		$(this).prev().hide();
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).prev().show();
		}
	})

	$("#email").blur(function() {

            ws.checkEmail($(this));

	})
    
    $("#regFrom").submit(function(){
        
        

        ws.checkEmail($("#email"));

        if(!$("#email").hasClass("error")){
            
         ws.checkPassword1($("#pword2"));
        ws.checkPassword($("#pword"));
        }
        
       

        if($(".error").length>0){
            return false;
        }else{
            return true;
        }


    })



}

ws.changePassword = function(){

    $("#email").blur(function() {

            ws.checkEmail2($(this));

        })

        $("#saveChange").click(function(){
        	
            ws.checkEmail2($("#email"));   
            if(!$("#email").hasClass("error")){
                
                ws.checkPassword1($("#pword2"));
                ws.checkPassword($("#pword"));
                ws.checkPassword($("#opass"));
            }
            
             if($(".error").length==0){
                	$.post("changePassword.action",{
                			mail:$("#email").val(),
                			oldPassword:$("#opass").val(),
                			newPassword:$("#pword").val(),
                			newPassword2:$("#pword2").val()
	                		},function(data){

	                						$("#saveChange").after('<span class="tip"><b class="ok"></b>密码修改成功</span>');
	                						$("#opass").val("");
                							$("#pword").val("");
                							$("#pword2").val("");
                							$("#email").focus();

		                	}).error(function() {

			                		$("#saveChange").after('<span class="tip"><b class="ok"></b>修改失败,请检查你输入的邮箱或密码。</span>')
				                	$("#opass").val("");
                							$("#pword").val("");
                							$("#pword2").val("");
                							$("#email").focus();
					                	})
             }
        })

}
var timer = null;
ws.effect =  function(){
	timer = window.setTimeout(function(){
			ws.showCloud()
			},4000)
}
ws.showMS2 = function(){
	
	$(".pic-sm2").animate({"margin-left": "0"}, 600,'swing');
	$(".msg-sm2").animate({"margin-left": "0"}, 700,'swing');
	$(".title-sm2").animate({"margin-left": "0"},800,'swing',function(){
		window.clearTimeout(timer)
		timer = window.setTimeout(function(){
			ws.showCloud()
		},4000)
	});
	
	
	
	
}
ws.showCloud = function(){
	$(".title-sm2").animate({"margin-left": "-1000px"},600,'swing');	
	$(".msg-sm2").animate({"margin-left": "-1000px"}, 800,'swing');
	$(".pic-sm2").animate({"margin-left": "-1000px"}, 1000,'swing',function(){
		window.clearTimeout(timer)
	window.setTimeout(function(){
			ws.showMS2()
	},4000)
	});
	

}